package com.qf.controller;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HellowController {
//    @Resource(name = "user1")
//    private User user;
//    @Value("${alibaba.ip}")
//    private String ip;
//    @Value("${alibaba.name}")
//    private String name;
//    @Value("${alibaba.password}")
//    private String password;

    @Autowired
    private UserDao userDao;

    @RequestMapping("/hello")
    public String hello(){
//        System.out.println("========="+ip);
//        System.out.println("========="+name);
//        System.out.println("========="+password);
//        System.out.println("========="+user);
        return "欢迎使用StringBoot";
    }

    @RequestMapping("/query")
    @ResponseBody
    public User query( int id){
        System.out.println("这是查找");
        User user1 = userDao.findId1(id);
        return user1;
    }
    @RequestMapping("/insert")
    @ResponseBody
    public User insert(@RequestBody User user){
        int count = userDao.insertUser1(user);
        System.out.println("这是添加");
        if (count>0){
            return user;
        }else {
            System.out.println("添加失败");
        }
        return null;
    }
}
